
import cv2
import numpy as np


flag = False
x1=y1=0


##Alt+3
def screenShot(event,x,y,flags,param):
  global x1,y1,flag,img,temp
  if event==cv2.EVENT_LBUTTONDOWN: 
    flag = True 
    x1 = x
    y1 = y
  elif event==cv2.EVENT_MOUSEMOVE: 
    if(flag):
       img = temp.copy()
       cv2.rectangle(img,(x1,y1),(x,y),(0,255,0),2)
  elif event==cv2.EVENT_LBUTTONUP: #
      flag = False
      ROI = temp[y1:y,x1:x] #---y1:y2, x1:x2
      img=temp.copy()
     # cv2.imshow('ROI',ROI)
      #cv2.imwrite('ROI.bmp',ROI)
#      cv2.rectangle(img,(x1,y1),(x,y),(0,255,0),2)
    
img=cv2.imread('images/a.jpg') #

temp = img.copy() #

cv2.namedWindow('screenShot')

cv2.setMouseCallback('screenShot',screenShot)

while(1):
  cv2.imshow('screenShot',img)
  if cv2.waitKey(1)&0xFF==27: #Esc�����˳�
    break
cv2.destroyAllWindows()





